<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
  <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
</head>
<body style="padding:10px;">
    <div class="tplay-body-div">
        <div class="layui-tab">
            <ul class="layui-tab-title">
                <li><a href="{:url('admin/goods/index')}" class="a_menu">骰盅管理</a></li>
                <li class="layui-this">修改骰盅</li>
            </ul>
        </div>

        <div style="margin-top: 20px;">
        </div>

        <form class="layui-form" id="admin">
            <input name="id" lay-verify="required" utocomplete="off" class="layui-input" type="hidden" value="{$info['id']}">

            <div class="layui-form-item">
                <label class="layui-form-label">道具编号</label>
                <div class="layui-input-inline">
                    <input name="image_id" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" type="text" value="{$info['image_id']}" >
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                    <input name="name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" type="text" value="{$info['name']}" >
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">价格</label>
                <div class="layui-input-inline">
                    <input name="price" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" type="text" value="{$info['price']}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">解锁方式</label>
                <div class="layui-input-inline">
                    <select name="unlock_way" lay-filter="aihao">
                        <option value="1" {if condition="$info.unlock_way eq '1'"}selected{/if}>旗力币购买</option>
                        <option value="2" {if condition="$info.unlock_way eq '2'"}selected{/if}>活动赠送</option >
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">描述简介</label>
                <div class="layui-input-inline">
                    <textarea  name="content" rows="5" cols="30">{$info['content']}</textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">库存</label>
                <div class="layui-input-inline">
                    <input name="storage" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" type="text" value="{$info['storage']}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">购买等级</label>
                <div class="layui-input-inline">
                    <select name="grade" lay-filter="aihao">
                        <option value="0" {if condition="$info.grade eq '0'"}selected{/if}>0</option>
                        <option value="1" {if condition="$info.grade eq '1'"}selected{/if}>1</option>
                        <option value="2"  {if condition="$info.grade eq '2'"}selected{/if}>2</option>
                        <option value="3"  {if condition="$info.grade eq '3'"}selected{/if}>3</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">是否购买</label>
                    <div class="layui-input-inline">
                    <select name="allow_buy" lay-filter="aihao">
                        <option value="1"  {if condition="$info.allow_buy eq '1'"}selected{/if} >允许</option>
                        <option value="0"  {if condition="$info.allow_buy eq '0'"}selected{/if} >禁止</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">是否赠送</label>
                <div class="layui-input-inline">
                    <select name="allow_send" lay-filter="aihao">
                        <option value="1" {if condition="$info.allow_send eq '1'"}selected{/if} >允许</option>
                        <option value="0" {if condition="$info.allow_send eq '0'"}selected{/if} >禁止</option>
                    </select>
                </div>
            </div>

            <div class="layui-upload">
                <button type="button" class="layui-btn" id="test2">图片上传</button>
                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                    预览图：
                    <div class="layui-upload-list" id="demo2">
                        <?php if(!empty($asr)){foreach ($asr as $key => $value)
                        { ?>
                        <img src="{$value}" class="layui-upload-img" onclick="removeImage(this)">
                        <input type="hidden" name="thumb[]" value="<?php echo $value ?>">
                        <?php }} ?>
                    </div>
                </blockquote>
            </div>

            <button type="button" class="layui-btn" id="test2">动态图</button>

            {if condition="$info.effect neq null"}
            <img src="{$info['effect']}" class="layui-upload-img">
            {/if}
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="admin">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>

        </form>

    </div>
</body>
</html>
<script src="__PUBLIC__/layui/layui.js"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script>
    var message;
    layui.config({
        base: '__JS__/',
        version: '1.0.1'
    }).use(['app', 'message'], function() {
        var app = layui.app,
                $ = layui.jquery,
                layer = layui.layer;
        //将message设置为全局以便子页面调用
        message = layui.message;
        //主入口
        app.set({
            type: 'iframe'
        }).init();
    });
    layui.use('upload', function(){
        var $ = layui.jquery
                ,upload = layui.upload;

        //多图片上传
        upload.render({

            elem: '#test2'
            ,url: "{:url('login/upload')}" //上传接口
            ,multiple: true
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    //console.log(index);
                    //console.log(file);
                    //console.log(result);
                    //alt="'+ result.name +'" value="'+ result.id +'"
                    //$('#demo2').append('<img src="'+ result +'" class="layui-upload-img">')

                });
            }
            ,done: function(res){
                if(res.code == 2) {
                    $('#demo2').append('<img src="'+ res.src +'" class="layui-upload-img" onclick="removeImage(this)">')
                    $('#demo2').append('<input type="hidden" name="thumb[]" value="'+ res.src +'">');

                } else {
                    layer.msg(res.msg);
                }
                //上传完毕
            }
        });

    });
    layui.use(['layer', 'form'], function() {
        var layer = layui.layer,
                $ = layui.jquery,
                form = layui.form;
        $(window).on('load', function() {
            form.on('submit(admin)', function(data) {
                $.ajax({
                    url:"{:url('admin/goods/publish')}",
                    data:$('#admin').serialize(),
                    type:'post',
                    async: false,
                    success:function(res) {
                        if(res.code == 1) {
                            layer.alert(res.msg, function(index){
                                location.href = res.url;
                            })
                        } else {
                            layer.msg(res.msg);
                        }
                    }
                })
                return false;
            });
        });
    });

    function removeImage(e)
    {
        if(!confirm("确定删除")){
            return;
        }
        var src = $(e).attr('src');
        /**
         * 获取thumb,然后删除
         */
        $("input[name^='thumb']").each(function(i, l){
            if(src == $(l).val()){
                $.post("{:url('Goods/deleteImage')}", {'image_url' : src}, function(result){});
                $(this).remove();
                $(e).remove();
            }
        });

        //删除路径图片

    }
</script>
